package com.mmall.common;

import com.google.common.collect.Sets;

import java.util.HashSet;
import java.util.Set;

public class Const {

    public static final String CURRENT_USER = "current_user";

    public static final String EMAIL = "email";

    public static final String USERNAME = "username";

    public static final String TOKEN_PREFIX = "token_";

    public interface RedisExtime{
        int SESSION_EXTIME = 60 * 30;//30分钟
    }


    public interface ProductListOrderBy{
        Set<String> PRICE_ASC_DESC = Sets.newHashSet("price_desc","price_asc");
    }

    public interface Cart {
        int checked = 1;//即购物车选中状态
        int un_checked = 0;//即购物车中未被选中

        String LIMIT_NUM_FAIL = "limit_num_fail";
        String LIMIT_NUM_SUCCESS = "limit_num_success";
    }
    public interface Role {
        int ROLE_CUSTOMER = 0;//普通用户
        int ROLE_ADMIN = 1;//管理员
    }

    public enum ProductStatus{
        ON_SALE(1,"在线")
        ;
        private String value;
        private int code;

        ProductStatus(int code, String value) {
            this.code = code;
            this.value = value;
        }

        public String getValue() {
            return value;
        }

        public int getCode() {
            return code;
        }
    }

    public enum OrderStatus{
        CANCELED(0,"已取消"),
        NO_PAY(10,"待支付"),
        PAID(20,"已支付"),
        SHIPPED(40, "已发货"),
        ORDER_SUCCESS(50, "订单完成"),
        ORDER_CLOSE(60,"订单关闭");

        OrderStatus(int code, String value) {
            this.code = code;
            this.value = value;
        }
        private String value;
        private int code;

        public String getValue() {
            return value;
        }

        public int getCode() {
            return code;
        }

        public static OrderStatus codeOf(int code) {
            for (OrderStatus orderStatus : values()) {
                if (orderStatus.getCode() == code) {
                    return orderStatus;
                }
            }
            throw new RuntimeException("没有找到对应的枚举类型："+code);
        }
    }

    public interface AlipayCallback{
        String WAIT_BUYER_PAY = "WAIT_BUYER_PAY";//交易创建，等待买家付款
        String TRADE_CLOSED = "TRADE_CLOSED";//未付款交易超时关闭，或支付完成后全额退款
        String TRADE_SUCCESS = "TRADE_SUCCESS";//交易支付成功
        String TRADE_FINISHED = "TRADE_FINISHED";//交易结束，不可退款

        String RESPONSE_SUCCESS = "success";
        String RESPONSE_FAILED = "failed";
    }

    //支付来源
    public enum PlatForm{
        ALIPAY(1,"支付宝")
        ;
        PlatForm(int code, String value) {
            this.code = code;
            this.value = value;
        }
        private String value;
        private int code;

        public String getValue() {
            return value;
        }

        public int getCode() {
            return code;
        }
    }
    //支付方式
    public enum PaymentType{
        ONLINE_PAY(1, "在线支付")
        ;
        PaymentType(int code, String value) {
            this.code = code;
            this.value = value;
        }
        private String value;
        private int code;

        public String getValue() {
            return value;
        }

        public int getCode() {
            return code;
        }

        public static PaymentType codeOf(int code) {
            for (PaymentType paymentType : values()) {
                if (paymentType.getCode() == code) {
                    return paymentType;
                }
            }
            throw new RuntimeException("没有找到对应的枚举类型："+code);
        }
    }

    public interface RedisLock{
        //关闭订单的分布式锁
        String CLOSE_ORDER_TASK_LOCK = "close_order_task_lock";
    }
}
